"""
练习01：使用dict.txt完成
编写一个函数：query_word
参数输入一个单词，调用函数在单词本查询这个单词
返回值是单词对应的那一行内容
提示：单词本每行一个单词
    单词按从小到大排序
    单词解释之间有空格
"""

# def query_word(word):
#     file = open("dict.txt") # 读打开
#     while True:
#         line = file.readline()
#         # 读到末尾结束循环
#         if not line:
#             break
#         # 第一个单词与输入的单词相同，返回一行数据
#         if line.split(" ")[0] == word:
#             return line

# def query_word(word):
#     file = open("dict.txt") # 读打开
#     while True:
#         line = file.readline()
#         # 读到末尾结束循环
#         if not line:
#             break
#         n = len(word)
#         if line[:n] == word and line[n] == " ":
#             return line

def query_word(word):
    file = open("dict.txt") # 读打开
    for line in file:
        tmp = line.split(" ")
        if tmp[0] > word:
            break
        elif tmp[0] == word:
            return line


print(query_word("abate"))
